<template>
  <div>
    <ul class="mui-table-view">
      <li class="mui-table-view-cell mui-media" v-for="(item, i) in newsList " :key="i">
        <router-link :to="'/home/newsInfo/' + i">
          <img class="mui-media-object mui-pull-left" :src="item.thumbnail_pic_s">
          <div class="mui-media-body">
            {{ item.title }}
            <p class="mui-ellipsis">
              <span>发表时间：{{ item.date }}</span>
              <span>点击：{{ click }}次</span>
            </p>
          </div>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import { Toast } from 'mint-ui'

export default {
  data() {
    return {
      day: new Date().toLocaleString(),
      click: Math.floor(Math.random() * 30) + 1,
      newsList: []
    }
  },
  created() {
    this.getNewsList()
  },
  methods: {
    getNewsList() {
      this.$http.get('../../data_file/old.json')
        .then(data => {
          console.log(data.body)
          var data = data.body
          if (data.error_code !== 0) {
            Toast({
              message: '加载新闻列表失败，请刷新重试···',
            })
          }
          this.newsList = data.result.data
        })
    }
    // getNewsList() {
    //   this.$http.jsonp('http://v.juhe.cn/toutiao/index?type=top&key=80bba82cb1f3b9e1a22158b2f4025918')
    //     .then(result => {
    //       console.log(result)
    //       // this.newsList = result.body.stories
    //     })
    // }
  }
}
</script>

<style lang="scss" scoped>
.mui-table-view {
  li {
    h1 {
      font-size: 14px;
    }
    .mui-ellipsis {
      font-size: 12px;
      color: #226aff;
      display: flex;
      justify-content: space-between;
    }
    .mui-media-body {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>
